package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsUserAccountMapper;
import com.qf.mapper.DtsUserMapper;
import com.qf.mapper.StatMapper;
import com.qf.pojo.*;
import com.qf.service.DtsUserService;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 千峰教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */

@Service
public class DtsUserServiceImpl implements DtsUserService {
    @Autowired
    DtsUserMapper userMapper;

    @Autowired
    StatMapper statMapper;

    @Override
    public Integer findTotal() {
        LambdaQueryWrapper<DtsUser> wrapper
                = new LambdaQueryWrapper<>();

        wrapper.eq(DtsUser::getDeleted ,false);

        Integer count = userMapper.selectCount(wrapper);

        return count;
    }

    @Override
    public List<DayStatis> queryDayStatis(int rang) {
        return statMapper.queryUserStatis(rang);
    }

    @Override
    public IPage<DtsUser> findPage(Integer page, Integer limit, String username, String mobile, String sort, String order) {
        IPage<DtsUser> iPage = new Page<>(page,limit);
        QueryWrapper<DtsUser> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(username)){
            wrapper.eq("username",username);
        }

        if(!StringUtils.isEmpty(mobile)){
            wrapper.eq("mobile",mobile);
        }

        if(order.equalsIgnoreCase("asc")){
            wrapper.orderByAsc(sort);
        }else {
            wrapper.orderByDesc(sort);
        }
        iPage = userMapper.selectPage(iPage, wrapper);
        return iPage;
    }

    @Override
    public List<Map> findAll(int statisDaysRang) {
        List<Map> maps=statMapper.selectAll(statisDaysRang);
        return maps;
    }


}
